/*
 * Copyright (c) 2016- 2020 qolome.com Inc. All Rights Reserved.
 * ProjectName: qolome-knowledge
 * FileName: CoursePackage.java
 * Author: jiangfeng@qolome.com
 * Date: 2020/3/11 上午8:19
 * LastModified: 2020/03/11 08:19:11
 */

package com.qolome.knowledge.design.pattern.composite.demo.transparent;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Qolome
 * @version V1.0
 * @Description 课程组合包
 * @date 2020年 03月11日 08:19:26
 */
@Slf4j
public class CoursePackage extends CourseComponet {

    private List<CourseComponet> courses = new ArrayList<>();

    private String name;
    private Integer level;

    public CoursePackage(String name, Integer level) {
        this.name = name;
        this.level = level;
    }

    @Override
    public void addChid(CourseComponet courseComponet) {
        courses.add(courseComponet);
    }

    @Override
    public void remoceChid(CourseComponet courseComponet) {
        courses.remove(courseComponet);
    }

    @Override
    public String getName(CourseComponet courseComponet) {
        return this.name;
    }

    @Override
    public void print() {
        log.info("name:{}", name);
        log.info("level:{}", level);
            printLine(level);
            for (CourseComponet courseComponet : courses) {
                courseComponet.print();
            }
        }

    private void printLine(int level){
        if(level!=0){
            StringBuilder printPath = new StringBuilder();
            for (int i = 0; i <level ; i++) {
                printPath.append("/--");
            }
            log.info(printPath.toString());
        }
        }
}
